home *** CD-ROM | disk | FTP | other *** search
/ LG Super CD / LG Super CD.iso / bitpim / bitpim-0.62-setup.exe / {app} / bitpim.exe / brewcompressedimage.pyo (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2003-11-06  |  4.8 KB  |  124 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.3)
  3.  
  4. import common
  5. import zlib
  6. from wxPython.wx import *
  7.  
  8. class Display(wxFrame):
  9.     
  10.     def __init__(self, file, parent = None):
  11.         bmp = getbitmap(file)
  12.         wxFrame.__init__(self, parent, -1, 'Image Display')
  13.         b = wxStaticBitmap(self, -1, bmp)
  14.         b.SetSize((bmp.GetWidth(), bmp.GetHeight()))
  15.         self.Fit()
  16.         self.Show(True)
  17.  
  18.  
  19.  
  20. class MyImage:
  21.     
  22.     def __init__(self, width, height, bytes, palette):
  23.         self.width = width
  24.         self.height = height
  25.         offset = 0
  26.         import cStringIO
  27.         data = cStringIO.StringIO()
  28.         for row in range(height):
  29.             while offset % 4 != 0:
  30.                 offset += 1
  31.             for col in range(width):
  32.                 v = ord(bytes[offset])
  33.                 offset += 1
  34.                 data.write(palette[v])
  35.             
  36.         
  37.         self.data = data.getvalue()
  38.  
  39.     
  40.     def toImage(self):
  41.         img = wxEmptyImage(self.width, self.height)
  42.         img.SetData(self.data)
  43.         return img
  44.  
  45.  
  46.  
  47. class BCIPalette:
  48.     
  49.     def __init__(self, data = ''):
  50.         pal = []
  51.         for offset in range(0, len(data), 4):
  52.             pal.append(data[offset + 2] + data[offset + 1] + data[offset])
  53.         
  54.         self.pal = pal
  55.  
  56.     
  57.     def __getitem__(self, e):
  58.         return self.pal[e]
  59.  
  60.  
  61.  
  62. def getimage(file):
  63.     f = open(file, 'rb')
  64.     data = f.read()
  65.     f.close()
  66.     palettes = { }
  67.     imageoffset = readlsb(data[8:11])
  68.     width = readlsb(data[14:16])
  69.     height = readlsb(data[16:18])
  70.     numitem1 = readlsb(data[18:20])
  71.     numitem2 = readlsb(data[20:22])
  72.     numitem3 = readlsb(data[22:24])
  73.     numpalettes = numitem1
  74.     numotherthing = numitem2
  75.     numimages = numitem3
  76.     bpp = readlsb(data[26:28])
  77.     offset = 28
  78.     for _ in range(numpalettes):
  79.         id = readlsb(data[offset:offset + 2])
  80.         offset += 2
  81.         numentries = readlsb(data[offset:offset + 2])
  82.         offset += 2
  83.         pal = BCIPalette(data[offset:offset + numentries * 4])
  84.         offset += numentries * 4
  85.         palettes[id] = pal
  86.     
  87.     for _ in range(numotherthing):
  88.         offset += 20
  89.     
  90.     for _ in range(numimages):
  91.         szdata = readlsb(data[offset:offset + 4])
  92.         width = readlsb(data[offset + 4:offset + 6])
  93.         height = readlsb(data[offset + 6:offset + 8])
  94.         id1 = readlsb(data[offset + 8:offset + 10])
  95.         id2 = readlsb(data[offset + 10:offset + 12])
  96.         offset += 12
  97.         buf = data[offset:offset + szdata]
  98.         res = zlib.decompress(buf)
  99.         img = MyImage(width, height, res, palettes[id2])
  100.         return img.toImage()
  101.     
  102.  
  103.  
  104. def readlsb(data):
  105.     res = 0
  106.     shift = 0
  107.     for i in data:
  108.         res |= ord(i) << shift
  109.         shift += 8
  110.     
  111.     return res
  112.  
  113. if __name__ == '__main__':
  114.     wxInitAllImageHandlers()
  115.     app = wxPySimpleApp()
  116.     if len(sys.argv) == 2:
  117.         f = Display(sys.argv[1])
  118.     elif len(sys.argv) == 3:
  119.         bciconvert(sys.argv[1], sys.argv[2])
  120.         f = Display(sys.argv[2])
  121.     
  122.     app.MainLoop()
  123.  
  124.